

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>dscribe.descriptors.elementaldistribution &mdash; DScribe 0.3.0a0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../_static/language_data.js"></script>
        <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/style.css" type="text/css" />
    <link rel="author" title="About these documents" href="../../../about.html" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html">
          

          
            
            <img src="../../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
              <div class="version">
                0.3.0a0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../../install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../tutorials/tutorials.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../doc/modules.html">Documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../contributing.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../citing.html">Citing DScribe</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../about.html">About</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">DScribe</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>dscribe.descriptors.elementaldistribution</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for dscribe.descriptors.elementaldistribution</h1><div class="highlight"><pre>
<span></span><span class="c1"># -*- coding: utf-8 -*-</span>
<span class="sd">&quot;&quot;&quot;Copyright 2019 DScribe developers</span>

<span class="sd">Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="sd">you may not use this file except in compliance with the License.</span>
<span class="sd">You may obtain a copy of the License at</span>

<span class="sd">    http://www.apache.org/licenses/LICENSE-2.0</span>

<span class="sd">Unless required by applicable law or agreed to in writing, software</span>
<span class="sd">distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="sd">WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="sd">See the License for the specific language governing permissions and</span>
<span class="sd">limitations under the License.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">scipy.special</span> <span class="k">import</span> <span class="n">erf</span>
<span class="kn">from</span> <span class="nn">scipy.sparse</span> <span class="k">import</span> <span class="n">lil_matrix</span>
<span class="kn">from</span> <span class="nn">dscribe.descriptors</span> <span class="k">import</span> <span class="n">Descriptor</span>


<div class="viewcode-block" id="ElementalDistribution"><a class="viewcode-back" href="../../../doc/dscribe.descriptors.html#dscribe.descriptors.elementaldistribution.ElementalDistribution">[docs]</a><span class="k">class</span> <span class="nc">ElementalDistribution</span><span class="p">(</span><span class="n">Descriptor</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Represents a generic distribution on any given grid for any given</span>
<span class="sd">    properties. Can create both continuos and discrete distributions.</span>

<span class="sd">    Continuous distributions require a standard deviation and the number of</span>
<span class="sd">    sampling points. You can also specify the minimum and maximum values for</span>
<span class="sd">    the axis. If these are not specified, a limit is selected based</span>
<span class="sd">    automatically on the values with:</span>

<span class="sd">        min = values.min() - 3*std</span>
<span class="sd">        max = values.max() + 3*std</span>

<span class="sd">    Discrete distributions are assumed to be integer values, and you only need</span>
<span class="sd">    to specify the values.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span>
            <span class="bp">self</span><span class="p">,</span>
            <span class="n">properties</span><span class="p">,</span>
            <span class="n">flatten</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
            <span class="n">sparse</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
            <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            properties(dict): Contains a description of the elemental property</span>
<span class="sd">                for which a distribution is created. Should contain a dictionary of</span>
<span class="sd">                the following form:</span>

<span class="sd">                properties={</span>
<span class="sd">                    &quot;property_name&quot;: {</span>
<span class="sd">                        &quot;type&quot;: &quot;continuous&quot;</span>
<span class="sd">                        &quot;min&quot;: &lt;Distribution minimum value&gt;</span>
<span class="sd">                        &quot;max&quot;: &lt;Distribution maximum value&gt;</span>
<span class="sd">                        &quot;std&quot;: &lt;Distribution standard deviation&gt;</span>
<span class="sd">                        &quot;n&quot;: &lt;Number of discrete samples from distribution&gt;</span>
<span class="sd">                        &quot;values&quot;: {</span>
<span class="sd">                            &quot;H&quot;: &lt;Value for hydrogen&gt;</span>
<span class="sd">                            ...</span>
<span class="sd">                        }</span>
<span class="sd">                    &quot;property_name2&quot;: {</span>
<span class="sd">                        &quot;type&quot;: &quot;discrete&quot;</span>
<span class="sd">                        &quot;values&quot;: {</span>
<span class="sd">                            &quot;H&quot;: &lt;Value for hydrogen&gt;</span>
<span class="sd">                            ...</span>
<span class="sd">                        }</span>
<span class="sd">                    }</span>
<span class="sd">                    }</span>
<span class="sd">                }</span>
<span class="sd">            flatten(bool): Whether to flatten out the result.</span>
<span class="sd">            sparse (bool): Whether the output should be a sparse matrix or a</span>
<span class="sd">                dense numpy array.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Check that the given properties are valid</span>
        <span class="k">for</span> <span class="n">prop_name</span><span class="p">,</span> <span class="n">prop_grid</span> <span class="ow">in</span> <span class="n">properties</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">dist_type</span> <span class="o">=</span> <span class="n">prop_grid</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;type&quot;</span><span class="p">)</span>
            <span class="n">valid_dist_types</span> <span class="o">=</span> <span class="nb">set</span><span class="p">([</span><span class="s2">&quot;continuous&quot;</span><span class="p">,</span> <span class="s2">&quot;discrete&quot;</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">dist_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">valid_dist_types</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s2">&quot;Please specify the distribution type. Valid options are: </span><span class="si">{}</span><span class="s2">&quot;</span>
                    <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">valid_dist_types</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="n">i_min</span> <span class="o">=</span> <span class="n">prop_grid</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;min&quot;</span><span class="p">)</span>
            <span class="n">i_max</span> <span class="o">=</span> <span class="n">prop_grid</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;max&quot;</span><span class="p">)</span>
            <span class="n">std</span> <span class="o">=</span> <span class="n">prop_grid</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;std&quot;</span><span class="p">)</span>
            <span class="n">n</span> <span class="o">=</span> <span class="n">prop_grid</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;n&quot;</span><span class="p">)</span>
            <span class="n">values</span> <span class="o">=</span> <span class="n">prop_grid</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;values&quot;</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">values</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                    <span class="s2">&quot;Please provide the property values, i.e. a dictionary that&quot;</span>
                    <span class="s2">&quot; maps an atomic element symbol to a property value.&quot;</span>
                <span class="p">)</span>

            <span class="n">values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">values</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>

            <span class="k">if</span> <span class="n">dist_type</span> <span class="o">==</span> <span class="s2">&quot;continuous&quot;</span><span class="p">:</span>
                <span class="n">true_min</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>
                <span class="n">true_max</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">i_min</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">i_min</span> <span class="o">=</span> <span class="n">true_min</span> <span class="o">-</span> <span class="mi">3</span><span class="o">*</span><span class="n">std</span>
                    <span class="n">prop_grid</span><span class="p">[</span><span class="s2">&quot;min&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">i_min</span>
                <span class="k">if</span> <span class="n">i_max</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">i_max</span> <span class="o">=</span> <span class="n">true_max</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">std</span>
                    <span class="n">prop_grid</span><span class="p">[</span><span class="s2">&quot;max&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">i_max</span>
                <span class="k">if</span> <span class="n">i_min</span> <span class="o">&gt;=</span> <span class="n">i_max</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s2">&quot;Minimum value for &#39;</span><span class="si">{}</span><span class="s2">&#39; cannot be larger or equal to maximum &quot;</span>
                        <span class="s2">&quot;value.&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">prop_name</span><span class="p">)</span>
                    <span class="p">)</span>
                <span class="k">if</span> <span class="n">std</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s2">&quot;The standard deviation must be a larger than zero.&quot;</span>
                    <span class="p">)</span>
                <span class="k">if</span> <span class="n">n</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s2">&quot;The number of grid points must be a non-negative &quot;</span>
                        <span class="s2">&quot;integer.&quot;</span>
                    <span class="p">)</span>
                <span class="k">if</span> <span class="n">true_min</span> <span class="o">&lt;</span> <span class="n">prop_grid</span><span class="p">[</span><span class="s2">&quot;min&quot;</span><span class="p">]:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s2">&quot;Property value is outside the specified minimum value.&quot;</span>
                    <span class="p">)</span>
                <span class="k">if</span> <span class="n">true_max</span> <span class="o">&gt;</span> <span class="n">prop_grid</span><span class="p">[</span><span class="s2">&quot;max&quot;</span><span class="p">]:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s2">&quot;Property value is outside the specified maximum value.&quot;</span>
                    <span class="p">)</span>
            <span class="k">elif</span> <span class="n">dist_type</span> <span class="o">==</span> <span class="s2">&quot;discrete&quot;</span><span class="p">:</span>

                <span class="c1"># Check that all values are integer</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">issubdtype</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">integer</span><span class="p">)</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">values</span><span class="p">):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s2">&quot;Not all the values given for property &#39;</span><span class="si">{}</span><span class="s2">&#39; are integer &quot;</span>
                        <span class="s2">&quot;numbers.&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">prop_name</span><span class="p">)</span>
                    <span class="p">)</span>
                <span class="n">i_min</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>
                <span class="n">i_max</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
                <span class="n">prop_grid</span><span class="p">[</span><span class="s2">&quot;min&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">i_min</span>
                <span class="n">prop_grid</span><span class="p">[</span><span class="s2">&quot;max&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">i_max</span>
                <span class="n">prop_grid</span><span class="p">[</span><span class="s2">&quot;n&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">i_max</span> <span class="o">-</span> <span class="n">i_min</span> <span class="o">+</span> <span class="mi">1</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">properties</span> <span class="o">=</span> <span class="n">properties</span>

<div class="viewcode-block" id="ElementalDistribution.get_number_of_features"><a class="viewcode-back" href="../../../doc/dscribe.descriptors.html#dscribe.descriptors.elementaldistribution.ElementalDistribution.get_number_of_features">[docs]</a>    <span class="k">def</span> <span class="nf">get_number_of_features</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Used to inquire the final number of features that this descriptor</span>
<span class="sd">        will have.</span>

<span class="sd">        Returns:</span>
<span class="sd">            int: Number of features for this descriptor.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">n_features</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">prop</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">n_features</span> <span class="o">+=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;n&quot;</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">n_features</span></div>

<div class="viewcode-block" id="ElementalDistribution.get_axis"><a class="viewcode-back" href="../../../doc/dscribe.descriptors.html#dscribe.descriptors.elementaldistribution.ElementalDistribution.get_axis">[docs]</a>    <span class="k">def</span> <span class="nf">get_axis</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">property_name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Used to return the used x-axis for the given property.</span>

<span class="sd">        Args:</span>
<span class="sd">            property_name(str): The property name that was used in the</span>
<span class="sd">            constructor.</span>

<span class="sd">        Returns:</span>
<span class="sd">            np.ndarray: An array of x-axis values.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">prop</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">[</span><span class="n">property_name</span><span class="p">]</span>
        <span class="n">minimum</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;min&quot;</span><span class="p">]</span>
        <span class="n">maximum</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;max&quot;</span><span class="p">]</span>
        <span class="n">dist_type</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">dist_type</span> <span class="o">==</span> <span class="s2">&quot;continuous&quot;</span><span class="p">:</span>
            <span class="n">n</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;n&quot;</span><span class="p">]</span>
            <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">minimum</span><span class="p">,</span> <span class="n">maximum</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">dist_type</span> <span class="o">==</span> <span class="s2">&quot;discrete&quot;</span><span class="p">:</span>
            <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">minimum</span><span class="p">,</span> <span class="n">maximum</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">x</span></div>

<div class="viewcode-block" id="ElementalDistribution.create"><a class="viewcode-back" href="../../../doc/dscribe.descriptors.html#dscribe.descriptors.elementaldistribution.ElementalDistribution.create">[docs]</a>    <span class="k">def</span> <span class="nf">create</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">system</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            system (:class:`ase.Atoms` | :class:`.System`): Input system.</span>

<span class="sd">        Returns:</span>
<span class="sd">            scipy.sparse.lil_matrix: The concatenated distributions of the</span>
<span class="sd">                specified properties in a sparse array.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">occurrence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_element_occurrence</span><span class="p">(</span><span class="n">system</span><span class="p">)</span>
        <span class="n">weights</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">occurrence</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
        <span class="n">n_features</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_number_of_features</span><span class="p">()</span>
        <span class="n">distribution</span> <span class="o">=</span> <span class="n">lil_matrix</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="n">n_features</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>

        <span class="n">index</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">prop</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">dist_type</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">dist_type</span> <span class="o">==</span> <span class="s2">&quot;continuous&quot;</span><span class="p">:</span>
                <span class="n">n</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;n&quot;</span><span class="p">]</span>
                <span class="n">minimum</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;min&quot;</span><span class="p">]</span>
                <span class="n">maximum</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;max&quot;</span><span class="p">]</span>
                <span class="n">std</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;std&quot;</span><span class="p">]</span>
                <span class="n">values</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;values&quot;</span><span class="p">]</span>
                <span class="n">centers</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">values</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">occurrence</span><span class="o">.</span><span class="n">keys</span><span class="p">()])</span>
                <span class="n">pdf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">gaussian_sum</span><span class="p">(</span><span class="n">centers</span><span class="p">,</span> <span class="n">weights</span><span class="p">,</span> <span class="n">minimum</span><span class="p">,</span> <span class="n">maximum</span><span class="p">,</span> <span class="n">std</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
                <span class="n">distribution</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">index</span><span class="p">:</span><span class="n">index</span><span class="o">+</span><span class="n">n</span><span class="p">]</span> <span class="o">+=</span> <span class="n">pdf</span>
                <span class="n">index</span> <span class="o">+=</span> <span class="n">n</span>
            <span class="k">elif</span> <span class="n">dist_type</span> <span class="o">==</span> <span class="s2">&quot;discrete&quot;</span><span class="p">:</span>
                <span class="n">n</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;n&quot;</span><span class="p">]</span>
                <span class="n">values</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;values&quot;</span><span class="p">]</span>
                <span class="n">hist</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n</span><span class="p">))</span>
                <span class="n">minimum</span> <span class="o">=</span> <span class="n">prop</span><span class="p">[</span><span class="s2">&quot;min&quot;</span><span class="p">]</span>
                <span class="k">for</span> <span class="n">element</span><span class="p">,</span> <span class="n">occ</span> <span class="ow">in</span> <span class="n">occurrence</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="p">[</span><span class="n">element</span><span class="p">]</span>
                    <span class="n">hist_index</span> <span class="o">=</span> <span class="n">value</span> <span class="o">-</span> <span class="n">minimum</span>
                    <span class="n">hist</span><span class="p">[</span><span class="n">hist_index</span><span class="p">]</span> <span class="o">=</span> <span class="n">occ</span>
                <span class="n">distribution</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">index</span><span class="p">:</span><span class="n">index</span><span class="o">+</span><span class="n">n</span><span class="p">]</span> <span class="o">+=</span> <span class="n">hist</span>
                <span class="n">index</span> <span class="o">+=</span> <span class="n">n</span>

        <span class="k">return</span> <span class="n">distribution</span></div>

<div class="viewcode-block" id="ElementalDistribution.gaussian_sum"><a class="viewcode-back" href="../../../doc/dscribe.descriptors.html#dscribe.descriptors.elementaldistribution.ElementalDistribution.gaussian_sum">[docs]</a>    <span class="k">def</span> <span class="nf">gaussian_sum</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">centers</span><span class="p">,</span> <span class="n">weights</span><span class="p">,</span> <span class="n">minimum</span><span class="p">,</span> <span class="n">maximum</span><span class="p">,</span> <span class="n">std</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculates a discrete version of a sum of Gaussian distributions.</span>

<span class="sd">        The calculation is done through the cumulative distribution function</span>
<span class="sd">        that is better at keeping the integral of the probability function</span>
<span class="sd">        constant with coarser grids.</span>

<span class="sd">        The values are normalized by dividing with the maximum value of a</span>
<span class="sd">        gaussian with the given standard deviation.</span>

<span class="sd">        Args:</span>
<span class="sd">            centers (1D np.ndarray): The means of the gaussians.</span>
<span class="sd">            weights (1D np.ndarray): The weights for the gaussians.</span>
<span class="sd">            minimum (float): The minimum grid value</span>
<span class="sd">            maximum (float): The maximum grid value</span>
<span class="sd">            std (float): Standard deviation of the gaussian</span>
<span class="sd">            n (int): Number of grid points</span>
<span class="sd">            settings (dict): The grid settings. A dictionary</span>
<span class="sd">                containing the following information:</span>

<span class="sd">        Returns:</span>
<span class="sd">            Value of the gaussian sums on the given grid.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">max_val</span> <span class="o">=</span> <span class="mi">1</span><span class="o">/</span><span class="p">(</span><span class="n">std</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="p">))</span>

        <span class="n">dx</span> <span class="o">=</span> <span class="p">(</span><span class="n">maximum</span> <span class="o">-</span> <span class="n">minimum</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="n">minimum</span><span class="o">-</span><span class="n">dx</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">maximum</span><span class="o">+</span><span class="n">dx</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">pos</span> <span class="o">=</span> <span class="n">x</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">,</span> <span class="p">:]</span> <span class="o">-</span> <span class="n">centers</span><span class="p">[:,</span> <span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">]</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">weights</span><span class="p">[:,</span> <span class="n">np</span><span class="o">.</span><span class="n">newaxis</span><span class="p">]</span><span class="o">*</span><span class="mi">1</span><span class="o">/</span><span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">erf</span><span class="p">(</span><span class="n">pos</span><span class="o">/</span><span class="p">(</span><span class="n">std</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">))))</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">/=</span> <span class="n">max_val</span>
        <span class="n">f_rolled</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">pdf</span> <span class="o">=</span> <span class="p">(</span><span class="n">f_rolled</span> <span class="o">-</span> <span class="n">f</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="n">dx</span>  <span class="c1"># PDF is the derivative of CDF</span>

        <span class="k">return</span> <span class="n">pdf</span></div>

<div class="viewcode-block" id="ElementalDistribution.get_element_occurrence"><a class="viewcode-back" href="../../../doc/dscribe.descriptors.html#dscribe.descriptors.elementaldistribution.ElementalDistribution.get_element_occurrence">[docs]</a>    <span class="k">def</span> <span class="nf">get_element_occurrence</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">system</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculate the count of each atomic element in the given system.</span>

<span class="sd">        Args:</span>
<span class="sd">            system (ase.Atoms): The atomic system.</span>

<span class="sd">        Returns:</span>
<span class="sd">            1D ndarray: The counts for each element in a list where the index</span>
<span class="sd">            of atomic number x is self.atomic_number_to_index[x]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">symbols</span> <span class="o">=</span> <span class="n">system</span><span class="o">.</span><span class="n">get_chemical_symbols</span><span class="p">()</span>
        <span class="n">unique</span><span class="p">,</span> <span class="n">counts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="n">symbols</span><span class="p">,</span> <span class="n">return_counts</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">occurrence</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">unique</span><span class="p">,</span> <span class="n">counts</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">occurrence</span></div></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  
  <div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
      <span class="fa fa-book"> Versions</span>
      v: 0.3.0a0
      <span class="fa fa-caret-down"></span>
    </span>
    <div class="rst-other-versions">
      <dl>
        <dt>Versions</dt>
        
          <dd><a href="https://singroup.github.io/dscribe/dev">0.3.0a0 (development)</a></dd>
        
          <dd><a href="https://singroup.github.io/dscribe">0.2.9 (latest stable)</a></dd>
        
      </dl>
    </div>
  </div>


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>